import app from './app.js'

import Vue from 'vue'
import Server from 'vue-server-renderer'
const renderer = Server.createRenderer()

app.get('*', (req, res) => {
  render(req, res)
})

function render(req, res){
  const App = new Vue({
    data(){
      return{
        url: req.url,
      }
    },
    template: `
      <div>
        <div>current URL:{{ url }}</div>
      </div>
    `,
  })
  renderer.renderToString(App, (err, html) => {
    if(err){
      res.status(500).end('Internal Server Error')
      return
    }else{
      res.end(`${html}`)
    }
  })
}